using System.Collections.Generic;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;

namespace MarriageFertility.Helpers
{
    public static class EquipmentUpdater
    {
        private static readonly EquipmentIndex[] WeaponSlots =
        {
            EquipmentIndex.WeaponItemBeginSlot,
            EquipmentIndex.Weapon1,
            EquipmentIndex.Weapon2,
            EquipmentIndex.Weapon3
        };

        private static readonly List<WeaponClass> ThrowingWeaponClasses = new()
        {
            WeaponClass.Stone,
            WeaponClass.Boulder,
            WeaponClass.ThrowingAxe,
            WeaponClass.ThrowingKnife,
            WeaponClass.Javelin
        };

        public static bool IsTooDifficult(ItemObject item, CharacterObject hero)
        {
            return item.Difficulty > 0 && item.Difficulty > hero.GetSkillValue(item.RelevantSkill);
        }

        private static bool IsThrowingWeapon(EquipmentElement element)
        {
            if (element.Item == null || element.Item.WeaponComponent == null) return false;
            var weaponClass1 = element.Item.WeaponComponent.PrimaryWeapon.WeaponClass;
            return ThrowingWeaponClasses.Contains(weaponClass1);
        }

        public static bool IsSameTypeWeapon(EquipmentElement element1, EquipmentElement element2)
        {
            if (element1.Item?.WeaponComponent == null || element2.Item?.WeaponComponent == null)
            {
                return false;
            }

            if (element1.Item.IsWeaponCouch() && !element2.Item.IsWeaponCouch()) return false;
            if (element2.Item.IsWeaponCouch() && !element1.Item.IsWeaponCouch()) return false;

            var weaponClass1 = element1.Item.WeaponComponent.PrimaryWeapon.WeaponClass;
            var weaponClass2 = element2.Item.WeaponComponent.PrimaryWeapon.WeaponClass;

            return weaponClass1 == weaponClass2 ||
                   (ThrowingWeaponClasses.Contains(weaponClass1) && ThrowingWeaponClasses.Contains(weaponClass2));
        }
        
    }
}